Skip to content

[TrimmableTypeMap] Scanner and JCW edge-case fixes#11096

Merged
simonrozsival merged 6 commits intomainfrom
dev/simonrozsival/trimmable-scanner-jcw-fixes
Apr 10, 2026
Merged

[TrimmableTypeMap] Scanner and JCW edge-case fixes#11096
simonrozsival merged 6 commits intomainfrom
dev/simonrozsival/trimmable-scanner-jcw-fixes

Conversation

@simonrozsival
Copy link
Copy Markdown
Member

@simonrozsival simonrozsival commented Apr 9, 2026

Summary

Fix scanner and JCW generation edge cases in the trimmable type map path.

This PR is now limited to the scanner/JCW fixes and associated regression tests.

Changes

  • Override detection across intermediate MCW bases

    • Continue walking base types when looking for inherited [Register] methods and properties, even when an intermediate DoNotGenerateAcw base sits between the concrete ACW and the original declaration.
    • Covers both normal and generic-instantiated base chains.
  • Deferred registerNatives() for Application / Instrumentation types

    • Generate lazy __md_registerNatives() calls for types that cannot safely register from a static initializer.
    • Keeps marshal methods wired up without eager static registration.
  • Proxy name sanitization cleanup

    • Sanitize generated proxy type names for generic managed types by replacing namespace / nesting / generic-arity separators and appending _Proxy in a dedicated ModelBuilder helper.
  • Regression tests

    • Add fixture hierarchies and unit coverage for:
      • override discovery through intermediate MCW bases
      • override discovery through generic intermediate bases
      • deferred registration behavior for Application / Instrumentation
      • CRC64 naming expectations for unregistered types

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes correctness gaps in the TrimmableTypeMap pipeline (scanner + generators) so the trimmable build path matches runtime behaviors and produces valid JCW/type-map outputs.

Changes:

  • Align CRC64 package naming with the runtime by switching to the Jones CRC64 implementation (Crc64Helper).
  • Improve override discovery by continuing base-hierarchy traversal past intermediate DoNotGenerateAcw MCW base types (including generic-instantiated bases).
  • Adjust JCW Java generation for Application/Instrumentation to use lazy __md_registerNatives() registration and sanitize proxy type names by removing generic arity backticks.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/TestFixtures/TestTypes.cs Adds new fixtures for Application/Instrumentation and intermediate MCW-base override scenarios.
tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Scanner/OverrideDetectionTests.cs Adds coverage for override detection across intermediate (including generic) MCW bases.
tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Scanner/JavaPeerScannerTests.cs Adds CRC64 expectation test to match JavaNativeTypeManager behavior.
tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/TypeMapAssemblyGeneratorTests.cs Verifies generated proxy type names don’t contain backticks and match sanitized naming.
tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/JcwJavaSourceGeneratorTests.cs Updates/extends assertions for Application/Instrumentation lazy native registration and new override fixtures.
src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/JavaPeerScanner.cs Removes DoNotGenerateAcw stop for method/property override discovery and switches CRC64 computation to Crc64Helper.
src/Microsoft.Android.Sdk.TrimmableTypeMap/Microsoft.Android.Sdk.TrimmableTypeMap.csproj Enables unsafe blocks and links in Java.Interop CRC64 helper sources.
src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/ModelBuilder.cs Sanitizes proxy type names by replacing generic arity backticks.
src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/Model/TypeMapAssemblyData.cs Updates documentation to reference TrimmableTypeMap.ActivateInstance.
src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/JcwJavaSourceGenerator.cs Implements lazy __md_registerNatives() path and injects registration before native callbacks when needed.

@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-scanner-jcw-fixes branch from d64ece1 to 6ccb7ca Compare April 9, 2026 08:23
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-typed-logger branch 2 times, most recently from 64cbe4d to 7443456 Compare April 9, 2026 08:28
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-scanner-jcw-fixes branch from 6ccb7ca to 3aa9b44 Compare April 9, 2026 08:28
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-typed-logger branch from 7443456 to 0342566 Compare April 9, 2026 08:30
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-scanner-jcw-fixes branch from 3aa9b44 to 8fd237a Compare April 9, 2026 08:30
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-typed-logger branch from 0342566 to d68d7df Compare April 9, 2026 08:32
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-scanner-jcw-fixes branch from 8fd237a to b82f717 Compare April 9, 2026 08:32
@simonrozsival simonrozsival added trimmable-type-map copilot `copilot-cli` or other AIs were used to author this labels Apr 9, 2026
Base automatically changed from dev/simonrozsival/trimmable-typed-logger to main April 9, 2026 14:29
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-scanner-jcw-fixes branch from b82f717 to 0768a52 Compare April 9, 2026 14:49
Copy link
Copy Markdown
Member Author

@simonrozsival simonrozsival left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review Summary

Verdict: ⚠️ Needs Changes

I didn’t spot a correctness bug in the scanner / JCW fixes themselves, but I did leave one targeted regression-coverage suggestion below. Public checks are green, however the internal Xamarin.Android-PR pipeline is still running, so this PR is not mergeable yet.

  • 💡 Testing: cover the ApplicationRegistration.registerApplications() half of the deferred-registration flow too (tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/JcwJavaSourceGeneratorTests.cs:315).

Nice cleanup overall — the override walk past intermediate MCW bases and the generic proxy-name sanitization both make sense.


Review generated by android-reviewer from review guidelines.

};

var java = GenerateToString (type);
AssertContainsLine ("__md_registerNatives ();\n\t\tn_OnCreate_Landroid_os_Bundle_ (p0);\n", java);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 💡 Testing — This nicely locks in the per-callback __md_registerNatives() fallback. Since CannotRegisterInStaticConstructor still also depends on ApplicationRegistration.registerApplications() for the startup path, consider adding one regression test for result.ApplicationRegistrationTypes or the generated ApplicationRegistration.java as well. That would keep both halves of the deferred-registration contract covered if this generator gets refactored again.

Rule: Add regression coverage for the full bug-fix path.

simonrozsival and others added 3 commits April 10, 2026 10:59
- CRC64 fix: Use Jones algorithm (Crc64Helper) matching the runtime,
  not System.IO.Hashing.Crc64
- Inherited override detection: Walk past DoNotGenerateAcw intermediate
  MCW base types when detecting method overrides
- JCW lazy registerNatives: Application/Instrumentation types use
  deferred __md_registerNatives() helper instead of static initializer
- Backtick sanitization: Clean generic arity markers in proxy type names

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-scanner-jcw-fixes branch from 682ebac to 2aeb243 Compare April 10, 2026 09:00
simonrozsival and others added 3 commits April 10, 2026 11:01
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival changed the title [TrimmableTypeMap] Scanner and JCW generator fixes [TrimmableTypeMap] Scanner and JCW edge-case fixes Apr 10, 2026
@simonrozsival simonrozsival merged commit 36e7c08 into main Apr 10, 2026
6 checks passed
@simonrozsival simonrozsival deleted the dev/simonrozsival/trimmable-scanner-jcw-fixes branch April 10, 2026 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot `copilot-cli` or other AIs were used to author this trimmable-type-map

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants